<?php
require_once APPLICATION_PATH . '/models/dishes.php';
class ManagedishesController extends Zend_Controller_Action
{
	public function indexAction()
	{
		//$model = $this->_getModel();
		$qmodel = new Model_Dishes();
		$this->view->entries = $qmodel->fetchEntries();
	}
	
	protected function _getDishesForm()
	{
		require_once APPLICATION_PATH . '/forms/fooditems.php';
        $form = new Form_fooditems();
        $form->setAction($this->_helper->url('save'));
        return $form;
	}
	
	public function saveAction()
    {
        $request = $this->getRequest();
        $form    = $this->_getDishesForm();
	/*	echo '<pre>';
        var_dump($form);
		exit;*/
        // check to see if this action has been POST'ed to
        if ($this->getRequest()->isPost()) {
            
            // now check to see if the form submitted exists, and
            // if the values passed in are valid for this form
            if ($form->isValid($request->getPost())) {
                
                // since we now know the form validated, we can now
                // start integrating that data sumitted via the form
                // into our model
                $model = $this->_getModel();
                $model->save($form->getValues());
                
                // now that we have saved our model, lets url redirect
                // to a new location
                // this is also considered a "redirect after post"
                // @see http://en.wikipedia.org/wiki/Post/Redirect/Get
                return $this->_helper->redirector('index');
            }
        }
        
        // assign the form to the view
        $this->view->form = $form;
    }
 protected function _getModel()
    {
        if (null === $this->_model) {
            // autoload only handles "library" compoennts.  Since this is an 
            // application model, we need to require it from its application 
            // path location.
            
            $this->_model = new Model_Dishes();
        }
        return $this->_model;
    }
public function deleteAction()
   {
   	$id = Zend_Controller_Request_Http::getQuery('item_id');
   $request = $this->getRequest();
   $model = $this->_getModel();
   
   
   $model->delete($id);
   return $this->_helper->redirector('index');
   
   }
}
?>